var url = 'http://hengzhi.ayvvv.com';
setTimeout(function () {
    // numberG();
})

function handle(keyword, order = "") {
    console.log(order)
    $.ajax({
        url: url + '/api/store/product/lst',
        type: 'get',
        dataType: 'json',
        data: {
            keyword: keyword,
            order: order
        },
        async: true,
        success: function (data) {
            console.log(data)
            if (data.status == 200) {
                console.log(data.data.count)
                var pagination = data.data.count;
                layui.use('laypage', function () {
                    var laypage = layui.laypage
                    laypage.render({
                        elem: 'box',
                        count: pagination,
                        jump: function (obj) {
                            console.log(obj.curr); //得到每页显示的条数
                            console.log(obj.curr)
                            var page = obj.curr;
                            $.ajax({
                                url: url + '/api/store/product/lst',
                                dataType: 'json',
                                type: 'get',
                                async: true,
                                data: {
                                    page: page,
                                    keyword: keyword,
                                    order: order
                                },
                                success: function (data) {
                                    if (data.status == 200) {
                                        $('#search').empty();
                                        let list = data.data.list;
                                        console.log(list)
                                        for (var i = 0; i < list.length; i++) {
                                            $('#search').append(`
                                            <div class="centu" >
                                            <div class="tu">
                                                    <img style="width:100px;height:100px;" src="` + list[i].image + `" alt="" />
                                            </div>
                                                <div class="p_name">
                                                    <a href="goods.html?product_id=` + list[i].product_id + `">` + list[i].store_name + `</a>
                                                </div>
                                                <div class="price">
                                                    <span style="color:#E4393C">￥<b style="font-size:16px">` + list[i].price + `</b></span>
                                                </div>
                                                </div>
                                          `);
                                        }
                                    }
                                }
                            })
                        }
                    });
                })
            }
        },
    });
    $('#up').click(function () {
        $("#search").empty();
        var order = 'price_asc';
        handle(keyword, order);
    });
    $('#dowww').click(function () {
        $("#search").empty();
        var order = 'price_desc';
        handle(keyword, order);
    })
    $('#ratee').click(function () {
        $("#search").empty();
        var order = 'rate';
        handle(keyword, order);
    })
    $('#newshang').click(function () {
        $("#search").empty();
        var order = 'is_new';
        handle(keyword, order);
    })
    $('#xiaoliang').click(function () {
        $("#search").empty();
        var order = 'sales';
        handle(keyword, order);
    })
}